import unittest
import requests
import ddt
import pandas as pd

addColumnSelf = pd.read_csv('./data/addColumnSelf.csv', na_filter=False)
df1 = pd.DataFrame(addColumnSelf)
da1 = df1.to_dict(orient="records")

comment = pd.read_csv('./data/comment.csv', na_filter=False)
df2 = pd.DataFrame(comment)
da2 = df2.to_dict(orient="records")


@ddt.ddt
class TestMethod(unittest.TestCase):
    @ddt.data(*da1)
    def testAddColumnSelf(self,da1):
        print("----testAddColumnSelf-----")
        r = requests.post('http://localhost:8081/column-self/add',data=da1).json()
        ret = {
            "msg": "新建专栏成功",
            "code": 0
        }
        self.assertDictEqual(ret, r)
        self.assertEqual(0, r.get("code"))

    @ddt.data(*da2)
    def testAddComment(self, da2):
        print("----testAddComment-----")
        r = requests.post('http://localhost:8081/comment/comment', data=da2).json()
        ret = {
            "msg": "评论成功",
            "code": 0
        }
        self.assertDictEqual(ret, r)
        self.assertEqual(0, r.get("code"))


    def testShowOnePost(self):
        print("----testShowOnePost-----")
        r = requests.post('http://localhost:8081/discussPost/showOnePost?id=1').json()
        self.assertEqual(0, r.get("code"))


    def testAddOrders1(self):
        print("----testAddOrders1-----")
        r = requests.post('http://localhost:8081/orders/addOrders?userId=1&discussPostId=4').json()
        ret = {
            "msg": "购买成功",
            "code": 0
        }
        self.assertDictEqual(ret, r)
        self.assertEqual(0, r.get("code"))

    def testAddOrders2(self):
        print("----testAddOrders2-----")
        r = requests.post('http://localhost:8081/orders/addOrders?userId=28&discussPostId=4').json()
        ret = {
            "msg": "购买成功",
            "code": 0
        }
        self.assertDictEqual(ret, r)
        self.assertEqual(0, r.get("code"))

if __name__ == "__main__":
    unittest.main()
